package giermala.dominik.fotka.controller;

import giermala.dominik.fotka.dao.FotoDao;
import giermala.dominik.fotka.domain.Foto;
import giermala.dominik.fotka.domain.User;

import java.util.List;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class CompareController {
	
	private static final Logger logger = LoggerFactory.getLogger(CompareController.class);

	@Autowired
	private FotoDao fotoDao;

	@RequestMapping(value = "/compare.html", method = RequestMethod.GET)
	public String getRandomFoto(Locale locale, Model model, HttpServletRequest request) {
		logger.info("Get Random Foto");
		User user = (User)request.getSession().getAttribute("user");
		model.addAttribute("userId", user.getId());
		
		List<Foto> fotos = fotoDao.find2RandomFotos();		
		model.addAttribute("foto_0", fotos.get(0));
		model.addAttribute("foto_1", fotos.get(1));
		
		return "compare";
	}	
}
